package mvp.com.bbc.rcjavaretrofitdaggermvp.presenter;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.contact.InfoContact;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.utils.NetworkUtil;
import mvp.com.bbc.rcjavaretrofitdaggermvp.model.InfoAddMode;

/**
 * Created by ${cbf} on 2017/11/27.
 */

public class InfoAddPresenter implements InfoContact.InfoAddPresenter {
    private InfoContact.InfoAddMode addMode;
    private InfoContact.InfoAddView addView;

    @Inject
    public InfoAddPresenter(InfoContact.InfoAddView addView) {
        this.addView = addView;
        this.addMode = new InfoAddMode();
    }

    @Override
    public void infoAddPresenter(String userid, String content) {
        addMode.infoAddMode(userid, content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull String s) {
                        addView.infoAddView(s);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        NetworkUtil.onError();

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
